package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
    @Insert("insert into orders" +
            "        (number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark," +
            "         phone, address,user_name, consignee, estimated_delivery_time, delivery_status, pack_amount, tableware_number," +
            "         tableware_status)" +
            "        values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod}," +
            "                #{payStatus}, #{amount}, #{remark}, #{phone}, #{address},#{userName},#{consignee}," +
            "                #{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Orders orders);

    @Select("select * from orders where user_id = #{currentId} and status=#{status} order by order_time desc")
    List<OrderVO> selectAll(Long currentId, Integer status);

    @Select("select * from orders where id = #{id}")
    Orders selectById(Integer id);
    @Select("select * from orders where user_id = #{currentId} order by order_time desc")
    List<OrderVO> select(Long currentId);

    void updateOrdersStstus(Orders order);

    List<OrderVO> selectPage(OrdersPageQueryDTO orders);

    @Select("select * from orders where user_id = #{currentId}")
    List<Orders> selectOrders(Long currentId);

    @Update("update orders set status = #{status} where order_time <= #{time}")
    void update(Integer status, LocalDateTime time);

    @Select("select * from orders")
    List<Orders> selectAllOreders();

    @Select("select * from orders where order_time between #{todayStart} and #{todayEnd}")
    List<Orders> selectUserCount(LocalDateTime todayStart, LocalDateTime todayEnd);

    @Select("select SUM(amount) from orders where status = 5 and order_time between #{todayStart} and #{todayEnd}")
    Double sum(LocalDateTime todayStart, LocalDateTime todayEnd);

    Double getByMapOrders(Map<String, Object> map);

    @Select("select * from orders where status = #{status} and order_time <= #{time}")
    List<Orders> selectStatus(Integer status, LocalDateTime time);

    List<Orders> getByMap(Map<String, Object> map);

    List<GoodsSalesDTO> selectOredersDetailTop10(LocalDateTime beginTime, LocalDateTime endTime);

}
